package com.acdc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.acdc.domain.OtaVersionFile;
import com.acdc.service.IOtaVersionFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import java.io.IOException;
/**
 * OTA版本Controller
 * 
 * @author acdc
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/ota/ota")
public class OtaVersionFileController extends BaseController
{
    @Autowired
    private IOtaVersionFileService otaVersionFileService;

    /**
     * 查询OTA版本列表
     */
    @PreAuthorize("@ss.hasPermi('ota:ota:list')")
    @GetMapping("/list")
    public TableDataInfo list(OtaVersionFile otaVersionFile)
    {
        startPage();
        List<OtaVersionFile> list = otaVersionFileService.selectOtaVersionFileList(otaVersionFile);
        return getDataTable(list);
    }

    /**
     * 导出OTA版本列表
     */
    @PreAuthorize("@ss.hasPermi('ota:ota:export')")
    @Log(title = "OTA版本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OtaVersionFile otaVersionFile)
    {
        List<OtaVersionFile> list = otaVersionFileService.selectOtaVersionFileList(otaVersionFile);
        ExcelUtil<OtaVersionFile> util = new ExcelUtil<OtaVersionFile>(OtaVersionFile.class);
        util.exportExcel(response, list, "OTA版本数据");
    }

    /**
     * 获取OTA版本详细信息
     */
    @PreAuthorize("@ss.hasPermi('ota:ota:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(otaVersionFileService.selectOtaVersionFileById(id));
    }

    /**
     * 新增OTA版本
     */
    @PreAuthorize("@ss.hasPermi('ota:ota:add')")
    @Log(title = "OTA版本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OtaVersionFile otaVersionFile)
    {
        try {
            return toAjax(otaVersionFileService.insertOtaVersionFile(otaVersionFile));
        } catch (IOException e) {
            return error(e.getMessage());
        }
    }

    /**
     * 修改OTA版本
     */
    @PreAuthorize("@ss.hasPermi('ota:ota:edit')")
    @Log(title = "OTA版本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OtaVersionFile otaVersionFile)
    {
        try {
            return toAjax(otaVersionFileService.updateOtaVersionFile(otaVersionFile));
        } catch (IOException e) {
            return error(e.getMessage());
        }
    }

    /**
     * 删除OTA版本
     */
    @PreAuthorize("@ss.hasPermi('ota:ota:remove')")
    @Log(title = "OTA版本", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(otaVersionFileService.deleteOtaVersionFileByIds(ids));
    }
}
